package com.itmk.web.adminInfo.service.impl;

import com.itmk.web.adminInfo.entity.EduInfo;
import com.itmk.web.adminInfo.entity.ForjInfo;
import com.itmk.web.adminInfo.mapper.AdminMapper;
import com.itmk.web.adminInfo.service.AdminService;
import com.itmk.web.ai.entity.Pdfs;
import com.itmk.web.companyInfo.entity.Company;
import com.itmk.web.companyInfo.entity.JobInfo;
import com.itmk.web.user.entity.UserLogin;
import com.itmk.web.userInfo.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Boolean addBasicInfo(BasicInfo basic) {
        return adminMapper.addBasicInfo(basic);
    }

    @Override
    public List<UserLogin> getAllUser(String signType) {
        return adminMapper.getAllUser(signType);
    }

    @Override
    public BasicInfo getBasicInfo(String uuid) {
        return adminMapper.getBasicInfo(uuid);
    }

    @Override
    public EduInfo getEduInfo(String uuid) {
        EduInfo eduInfo = adminMapper.getEduInfo(uuid);
        Undergo undergo = new Undergo();
        undergo.setStart(eduInfo.getUndergoStart());
        undergo.setEnd(eduInfo.getUndergoEnd());
        eduInfo.setUndergo(undergo);
        return eduInfo;
    }

    @Override
    public ForjInfo getForJobInfo(String uuid) {
        ForjInfo result = adminMapper.getForJobInfo(uuid);
        Salary salary = new Salary();
        salary.setMsalaryMax(result.getMsalaryMax());
        salary.setMsalaryMin(result.getMsalaryMin());
        salary.setDsalaryMax(result.getDsalaryMax());
        salary.setDsalaryMin(result.getDsalaryMin());
        salary.setNumMouth(result.getNumMouth());
        result.setSalary(salary);
        return result;
    }

    @Override
    public Pdfs getResumePdf(String uuid) {
        return adminMapper.getResumePDF(uuid);
    }

    @Override
    public List<ProjectExperience> getProExperience(String uuid) {
        List<ProjectExperience> result = adminMapper.getProExperience(uuid);
        for (ProjectExperience pe : result) {
            Time time = new Time();
            time.setStart(pe.getTimeStart());
            time.setEnd(pe.getTimeEnd());
            pe.setTime(time);
        }
        return result;
    }

    @Override
    public List<JobExperience> getJobExperience(String uuid) {
        List<JobExperience> result = adminMapper.getJobExperience(uuid);
        for (JobExperience pe : result) {
            Time time = new Time();
            time.setStart(pe.getTimeStart());
            time.setEnd(pe.getTimeEnd());
            pe.setTime(time);
        }
        return result;
    }

    @Override
    public Boolean updateBasicInfo(BasicInfo basicInfo) {
        return adminMapper.updateBasicInfo(basicInfo);
    }

    @Override
    public Boolean deleteBasicInfo(String uuid) {
        return adminMapper.deleteBasicInfo(uuid);
    }

    @Override
    public UserLogin getUser(String uuid) {
        return adminMapper.getUser(uuid);
    }

    @Override
    public Boolean updateEduInfo(EduInfo eduInfo) {
        return adminMapper.updateEduInfo(eduInfo);
    }

    @Override
    public Boolean deleteEduInfo(String uuid) {
        return adminMapper.deleteEduInfo(uuid);
    }

    @Override
    public Boolean addEduInfo(EduInfo educationInfo) {
        return adminMapper.addEduInfo(educationInfo);
    }

    @Override
    public Boolean updateForJobInfo(ForjInfo forjInfo) {
        return adminMapper.updateForJobInfo(forjInfo);
    }

    @Override
    public Boolean deleteForJobInfo(String uuid) {
        return adminMapper.deleteForJobInfo(uuid);
    }

    @Override
    public Boolean addForJobInfo(ForjInfo forjInfo1) {
        return adminMapper.addForJobInfo(forjInfo1);
    }

    @Override
    public String checkFile(String uuid) {
        return adminMapper.checkFile(uuid);
    }

    @Override
    public void updateResume(String fileName, String uuid) {
        adminMapper.updateResume(fileName,uuid);
    }

    @Override
    public Boolean deleteResumePDF(String uuid) {
        return adminMapper.deleteResumePDF(uuid);
    }

    @Override
    public Boolean updateProExerience(ProjectExperience pe) {
        return adminMapper.updateProExperience(pe);
    }

    @Override
    public Boolean deleteProExerience(ProjectExperience pe) {
        return adminMapper.deleteProExperience(pe);
    }

    @Override
    public Boolean addProExerience(ProjectExperience pe) {
        return adminMapper.addProExperience(pe);
    }

    @Override
    public Boolean updateJobExerience(JobExperience je) {
        return adminMapper.updateJobExperience(je);
    }

    @Override
    public Boolean deleteJobExerience(JobExperience je) {
        return adminMapper.deleteJobExperience(je);
    }

    @Override
    public Boolean addJobExerience(JobExperience je) {
        return adminMapper.addJobExperience(je);
    }

    @Override
    public Company getCompanyInfo(String uuid) {
        return adminMapper.getCompanyInfo(uuid);
    }

    @Override
    public Boolean updateCompanyInfo(Company company) {
        return adminMapper.updateCompanyInfo(company);
    }

    @Override
    public String checkPic(String uuid) {
        return adminMapper.checkPic(uuid);
    }

    @Override
    public void updatePic(String fileName, String uuid) {
        adminMapper.updatePic(fileName,uuid);
    }

    @Override
    public List<JobInfo> getJobInfo(String uuid) {
        return adminMapper.getJobInfo(uuid);
    }

    @Override
    public Boolean updateJobInfo(JobInfo jobInfo) {
        return adminMapper.updateJobInfo(jobInfo);
    }

    @Override
    public Boolean deleteJobInfo(JobInfo jobInfo) {
        return adminMapper.deleteJobInfo(jobInfo);
    }

    @Override
    public Boolean addJobInfo(JobInfo jobInfo) {
        return adminMapper.addJobInfo(jobInfo);
    }

    @Override
    public List<String> getResumeOfJob(String jobUuid) {
        return adminMapper.getResumeOfJob(jobUuid);
    }

    @Override
    public boolean addResumeOfJob(String companyUUID, String userUUID, String jobUUID) {

        JobInfo jobinfo = adminMapper.getJobOneInfo(companyUUID,jobUUID);
        String oldResume = jobinfo.getResumes();
        String newResume;
        if(oldResume==null){
            newResume = userUUID;
        }else{
            newResume = oldResume+","+userUUID;
        }
        return adminMapper.addResumeOfJob(jobUUID,newResume);
    }

    @Override
    public JobInfo getJobOneInfo(String uuid, String jobUUID) {
        return adminMapper.getJobOneInfo(uuid,jobUUID);
    }

//    @Override
//    public List<String> getCommonImages() {
//        return adminMapper.getCommonImages();
//    }
}
